package com.ziq.zcamp.util

import android.Manifest
import android.view.Gravity
import androidx.fragment.app.FragmentActivity
import com.ziq.base.extension.dp
import com.ziq.base.utils.permission.PermissionRemindPopupWindow
import com.ziq.base.utils.permission.PermissionUtil

class PermissionHelper {

    companion object {

        var storagePermission = arrayOf(
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE
        )

        fun requestStoragePermission(activity: FragmentActivity, onGrant :(()->Unit)? = null, onReject :(()->Unit)? = null, onRemind :(()->Unit)? = {
            if(!activity.isFinishing){
                val remindPopupWindow = PermissionRemindPopupWindow(activity, "位置权限被禁用", "请到设置中授予获取位置的权限")
                remindPopupWindow.showAtLocation(activity.window.decorView, Gravity.TOP, 0, 50.dp)
            }
        }){
            PermissionUtil.requestPermission(
                activity, storagePermission,
                title = "位置权限使用说明",
                content = "用于为您推荐附近的信息，或帮助您在发布的信息中展示位置",
                onGrant = onGrant, onReject = onReject, onRemind = onRemind
            )
        }
    }

}